<template>
    <div>

        <div style="margin: 10px 0">
            <el-input style="width: 200px" placeholder="请输入公司" suffix-icon="el-icon-search"
                      v-model="company"></el-input>
            <el-input style="width: 200px" placeholder="请输入订单状态" suffix-icon="el-icon-search"
                      v-model="status"></el-input>
            <!--<el-input style="width: 200px" placeholder="请输入邮箱" suffix-icon="el-icon-search" class="ml-5" v-model="email"></el-input>-->
            <!--<el-input style="width: 200px" placeholder="请输入地址" suffix-icon="el-icon-search" class="ml-5" v-model="address"></el-input>-->
            <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
            <el-button type="warning" @click="reset">重置</el-button>
        </div>

        <!--<div style="margin: 10px 0">-->
            <!--<el-button type="primary" @click="handleAdd">新增 <i class="el-icon-circle-plus-outline"></i></el-button>-->
            <!--<template>-->
                <!--<el-popconfirm-->
                        <!--class="ml-5"-->
                        <!--confirm-button-text='确定'-->
                        <!--cancel-button-text='我再想想'-->
                        <!--icon="el-icon-info"-->
                        <!--icon-color="red"-->
                        <!--title="确定删除吗？"-->
                        <!--@confirm="delBatch"-->
                <!--&gt;-->
                    <!--<el-button type="danger" slot="reference">批量删除 <i class="el-icon-remove-outline"></i></el-button>-->
                <!--</el-popconfirm>-->
            <!--</template>-->
        <!--</div>-->

        <el-table :data="tableData" border stripe :header-cell-class-name="'headerBg'"
                  @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="id" label="ID" width="40"></el-table-column>
            <el-table-column prop="type" label="类型" width="50"></el-table-column>
            <el-table-column prop="email" label="邮箱" width="100"></el-table-column>
            <el-table-column prop="contactPerson" label="联系人" width="70"></el-table-column>
            <el-table-column prop="phone" label="电话" width="100"></el-table-column>
            <el-table-column prop="company" label="公司" width="100"></el-table-column>
            <el-table-column prop="destination" label="目的地" width="70"></el-table-column>
            <el-table-column prop="tamount" label="卡车数量" width="50"></el-table-column>
            <el-table-column prop="tdetail" label="卡车备注" width="50"></el-table-column>
            <el-table-column prop="damount" label="卸箱数" width="70"></el-table-column>
            <el-table-column prop="pamount" label="装箱数" width="70"></el-table-column>
            <el-table-column prop="updateTime" label="更新时间" width="90"></el-table-column>
            <el-table-column prop="arrangeTime" label="到达时间" width="90"></el-table-column>
            <el-table-column prop="finishTime" label="完成时间" width="90"></el-table-column>
            <el-table-column prop="status" label="状态" width="50"></el-table-column>
            <el-table-column label="操作" width="300" align="center">
                <template slot-scope="scope">
                    <el-button type="success" @click="handleEdit(scope.row)">编辑 <i class="el-icon-edit"></i></el-button>
                    <!--<template>-->
                        <!--<el-popconfirm-->
                                <!--class="ml-5"-->
                                <!--confirm-button-text='确定'-->
                                <!--cancel-button-text='我再想想'-->
                                <!--icon="el-icon-info"-->
                                <!--icon-color="red"-->
                                <!--title="确定删除吗？"-->
                                <!--@confirm="del(scope.row.id)"-->
                        <!--&gt;-->
                            <!--<el-button type="danger" slot="reference">删除 <i class="el-icon-remove-outline"></i>-->
                            <!--</el-button>-->
                        <!--</el-popconfirm>-->
                    <!--</template>-->
                    <!--<template>-->
                        <!--<el-button class="ml-5" type="success">详情 <i class="el-icon-edit"></i></el-button>-->
                    <!--</template>-->
                </template>
            </el-table-column>
        </el-table>
        <div style="padding: 10px 0">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pageNum"
                    :page-sizes="[5, 10, 20, 50]"
                    :page-size="5"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>

        <el-dialog title="订单信息" :visible.sync="dialogFormVisible" width="30%">
            <el-form label-width="80px">
                <el-form-item label="订单状态" style="width: 71%">
                    <el-input v-model="form.status" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="到达时间">
                    <template>
                        <el-date-picker
                                v-model="form.arrangeTime"
                                type="datetime"
                                placeholder="选择日期时间">
                        </el-date-picker>
                    </template>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取消</el-button>
                <el-button type="primary" @click="save">确定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {serverIp, serverPort} from "../config/config";

    export default {
        name: 'Home',
        data() {
            return {
                serverIp: serverIp,
                serverPort: serverPort,
                tableData: [],
                total: 0,
                pageNum: 1,
                pageSize: 5,
                company: "",
                form: {},
                dialogFormVisible: false,
                multipleSelection: [],
                type: 3,
                enabled: this.form,
                enablep: true,
                status: "",

                // 日期
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() > Date.now();
                    },
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                value1: '',
                value2: '',

                // 时间
                startTime: '',
            }
        },
        created() {
            this.load()
        },
        methods: {
            load() {
                this.request.get("/admin/order/page", {
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        company: this.company,
                        status: this.status
                    }
                }).then(res => {
                    this.tableData = res.data.data
                    this.total = res.data.total
                })
            },
            reset() {
                this.company = ""
                this.load()
            },
            handleSizeChange(pageSize) {
                this.pageSize = pageSize;
                this.load()
            },
            handleCurrentChange(pageNum) {
                this.pageNum = pageNum;
                this.load()
            },
            handleSelectionChange(val) {
                this.multipleSelection = val
            },
            handleAdd() {
                this.form = {}
                this.dialogFormVisible = true
            },
            save() {
                if (this.form.arrangeTime && this.form.arrangeTime.toString().length > 20) {
                    // console.log(this.form.arrangeTime)
                    this.form.arrangeTime = this.form.arrangeTime.Format('yyyy-MM-dd hh:mm:ss')
                }
                this.request.post("/admin/order", this.form).then(res => {
                    if (res.code === '200') {
                        this.$message.success("保存成功")
                        this.dialogFormVisible = false
                        this.load()
                    } else {
                        this.$message.error("保存失败")
                    }
                })
            },
            handleEdit(row) {
                this.form = row
                this.dialogFormVisible = true
            },
            del(id) {
                this.request.get("/admin/order/delete?id=" + id).then(res => {
                    if (res.data) {
                        this.$message.success("删除成功")
                        this.load()
                    } else {
                        this.$message.error("删除失败")
                    }
                })
            },
            delBatch() {
                let ids = this.multipleSelection.map(v => v.id)
                this.request.post("/admin/order/delete/batch", ids).then(res => {
                    if (res.data) {
                        this.$message.success("删除成功")
                        this.load()
                    } else {
                        this.$message.error("删除失败")
                    }
                })
            },
            jyf() {
                alert(enabled)
                if (this.type == 1) {
                    this.enabled = true
                    this.enablep = false

                }
                if (this.type == 2) {
                    this.enabled = false
                    this.enablep = true
                }
                if (this.type == 3) {
                    this.enabled = true
                    this.enablep = true
                }
            }
        }
    }
</script>

<style>
    .headerBg {
        background: #eee !important;
    }
</style>
